/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.open.api.core.service;

import info.peigen.hotpot.component.open.api.core.service.base.AbstractOpenApiProcessorService;
import info.peigen.hotpot.component.open.api.facade.order.OpenApiOrder;
import info.peigen.hotpot.component.open.api.facade.processor.base.OpenApiProcessorServiceContext;
import info.peigen.hotpot.component.open.api.facade.result.OpenListResult;
import info.peigen.hotpot.component.open.api.facade.result.OpenPageResult;
import info.peigen.hotpot.component.open.api.facade.result.OpenSingleResult;
import org.noear.solon.annotation.Component;


/**
 * <b>(OpenSimpleApiService)</b>
 * <p>
 * 不需要验证的接口
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/9/20
 */
@SuppressWarnings({"rawtypes", "unchecked"})
@Component
public class OpenSimpleApiService extends AbstractOpenApiProcessorService {
    /**
     * @param order OpenApiOrder
     *
     * @return OpenSingleResult
     */
    public OpenSingleResult service(OpenApiOrder order) {
        OpenApiProcessorServiceContext serviceContext = OpenApiProcessorServiceContext.builder().order(order)
                .result(new OpenSingleResult()).build();
        executeForSimple(serviceContext, clojure -> {
        });

        parseToken(serviceContext, order, serviceContext.getResult());
        return (OpenSingleResult) serviceContext.getResult();
    }

    public OpenListResult listService(OpenApiOrder order) {
        OpenApiProcessorServiceContext serviceContext = OpenApiProcessorServiceContext.builder().order(order)
                .result(new OpenListResult()).build();
        executeForList(serviceContext, clojure -> {
        });

        parseToken(serviceContext, order, serviceContext.getResult());
        return (OpenListResult) serviceContext.getResult();
    }

    public OpenPageResult pageService(OpenApiOrder order) {
        OpenApiProcessorServiceContext serviceContext = OpenApiProcessorServiceContext.builder().order(order)
                .result(new OpenPageResult()).build();
        executeForPage(serviceContext, clojure -> {
        });

        parseToken(serviceContext, order, serviceContext.getResult());
        return (OpenPageResult) serviceContext.getResult();
    }
}